package com.project.controller;

import com.project.dao.ContentNRDao;
import com.project.dao.ContentRDao;
import com.project.entity.ContentNREntity;
import com.project.entity.ContentREntity;
import com.project.util.ConvertBeanUtil;
import com.project.util.SnowIdUtils;
import com.project.vo.ContentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("content")
public class ContentController {
    @Autowired
    private ContentNRDao contentNRDao;
    @Autowired
    private ContentRDao contentRDao;

    @RequestMapping("getFontInContent")
    public void getFontInContent(ContentVO contentVO){
        String contentId = SnowIdUtils.uniqueLongHex();
        ContentREntity contentREntity=  ConvertBeanUtil.copy(contentVO,
                ContentREntity.class,(convertBefore, convertAfter) -> {
                    convertAfter.setContentId(contentId);
                });
        ContentNREntity contentNREntity=  ConvertBeanUtil.copy(contentVO,
                ContentNREntity.class,(convertBefore, convertAfter) -> {
                    convertAfter.setContentId(contentId);
                });
        //持久化到数据库
        contentRDao.save(contentREntity);
        contentNRDao.save(contentNREntity);
        System.err.println(contentVO);
    }

}
